package message

import (
	"context"

	"gitee.com/liuxuezhan/ar-platform/admin-api/pkg/code"
	"gitee.com/liuxuezhan/ar-platform/rpc-client/setting/client/message"
	"gitee.com/liuxuezhan/ar-platform/rpc-client/setting/rpc"
	"github.com/zeromicro/go-zero/core/logc"

	"gitee.com/liuxuezhan/ar-platform/admin-api/internal/svc"
	"gitee.com/liuxuezhan/ar-platform/admin-api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type NotificationMessageUpdateLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

// 修改通知消息
func NewNotificationMessageUpdateLogic(ctx context.Context, svcCtx *svc.ServiceContext) *NotificationMessageUpdateLogic {
	return &NotificationMessageUpdateLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *NotificationMessageUpdateLogic) NotificationMessageUpdate(req *types.UpdateNotificationMessageReq) (resp *types.Empty, err error) {
	if req.Id == 0 {
		return nil, code.ParamsInvalid
	}

	u, err := l.svcCtx.SettingService.Message.NotificationMessageUpdate(l.ctx, &message.UpdateNotificationMessageReq{
		Id: req.Id,
		Data: &message.AddNotificationMessageReq{
			MerchantId: 1,                                          // 商户ID
			Language:   req.Data.Language,                          // 语言
			Type:       rpc.NotificationMessageType(req.Data.Type), // 类型,1:会员注册,2:账号充值,3:申请提现,4:提现到账,5:登录通知,6:XOSO期号取消通知,7:修改密码
			Title:      req.Data.Title,                             // 标题
			Content:    req.Data.Content,                           // 内容
		},
	})

	if err != nil {
		logc.Error(l.ctx, "NotificationMessageInfo err:", err)
		return nil, err
	}

	if u.Code != int64(code.SettingRpcSuccessful.Code()) {
		return nil, code.BusinessFailure
	}

	resp = &types.Empty{}
	return
}
